using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.MiniJSON;

public class GameOver : MonoBehaviour
{
//    bool shareNbr = true;
	private string fbGameDescMessage="";
	
    // Use this for initialization
    void Start() {
        
    }

    // Update is called once per frame
    void Update()
    {
        if( Helper.CheckTouch(gameObject) ) {
			if(gameObject.tag == "menu")
				Application.LoadLevel( "Menu" );
			else if(gameObject.tag == "share") {
				//tähän jako etc muu feedbackki jaosta
				switch(GM.LastGame){
				case "Pairs":
					fbGameDescMessage="Etsi pari";
				break;
				case "Colors":
					fbGameDescMessage="Tee per&auml;ss&auml;";
				break;
				case "Space":
					fbGameDescMessage="Ota koppi";
				break;
				default:break;
				}
				
				FB.Feed (
				    link:"https://www.facebook.com/Taitaja",
					linkName:"Taitaja2014",
					linkCaption:"Taitaja2014-mobiilipeli",
					linkDescription:"Sain Taitaja2014 "+fbGameDescMessage +" peliss&auml; "+ GM.LastScore + " pistett&auml;. Pystytk&ouml; parempaan?",
					callback: fbCallBack);
			}
			else
				Application.LoadLevel( GM.LastGame );
		}
			
    }
	
//	void OnMouseDown() 
//	{
//		if(gameObject.tag == "menu")
//			Application.LoadLevel( "Menu" );
//		else if(gameObject.tag == "share") {
//				//tähän jako etc muu feedbackki jaosta
//			switch(GM.LastGame){
//			case "Pairs":
//				fbGameDescMessage="Etsi pari";
//			break;
//			case "Colors":
//				fbGameDescMessage="Tee per&auml;ss&auml;";
//			break;
//			case "Space":
//				fbGameDescMessage="Ota koppi";
//			break;
//			default:break;
//			}
//			FB.Feed (
//			    link:"https://www.facebook.com/Taitaja",
//				linkName:"Taitaja2014",
//				linkCaption:"Taitaja2014-mobiilipeli",
//				linkDescription:"Sain Taitaja2014 "+fbGameDescMessage +" peliss&auml; "+ GM.LastScore + " pistett&auml;. Pystytk&ouml; parempaan?",
//				callback: fbCallBack);
//		}
//		else
//			Application.LoadLevel( GM.LastGame );
//				
//	}
	
    public void fbCallBack(FBResult result)
	{
		Dictionary<string,object> resDict;
		resDict = Json.Deserialize( result.Text ) as Dictionary<string, object>;
		
		renderer.enabled = false;
		
		// {"cancelled":true}
		if( resDict.ContainsKey("cancelled") && (bool)resDict["cancelled"] ) {
			renderer.enabled = true;
		}

	}
	
    IEnumerator wait() {
        yield return new WaitForSeconds(5);
        
    }
}
